/*
** bind_socket.c for  in /home/faye_m//tmp/zappy-2011/new_server/src/zappy-2011/new_server/src
** 
** Made by mouhamed faye
** Login   <faye_m@epitech.net>
** 
** Started on  Sun Jul 10 12:10:34 2011 mouhamed faye
** Last update Sun Jul 10 12:11:39 2011 mouhamed faye
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "types.h"
#include "parser.h"

void    bind_socket(T_env *e, t_server_params *p)
{
  e->serveraddr.sin_family = AF_INET;
  e->serveraddr.sin_addr.s_addr = INADDR_ANY;
  e->serveraddr.sin_port = htons(e->port);
  memset(&(e->serveraddr.sin_zero), '\0', 8);
  if (bind(e->listener, (struct sockaddr *)&e->serveraddr,
	sizeof(e->serveraddr)) == -1)
    {
      printf("bind error fonction binsocket : SEGFAULT DIRECT ...\n");
      exit(0);
    }
  if (listen(e->listener, 1024) == -1)
    printf("fonction binsocket : SEGFAULT DIRECT .....\n");
}
